package FlowGraph;

import java.io.*;
import FlowGraph.EdgeInfo.EdgeInfo;

//////////////////////////////////////////////////////////////////////////
//// FlowGraphEdge
/**

@author Ivan Jeukens
@version v 0.1 17/07/2002
*/
public class FlowGraphEdge  {

    public FlowGraphEdge(FlowGraphNode from, FlowGraphNode to) {
        _to = to;
        _from = from;
    }

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void setTo(FlowGraphNode to) {
        _to = to;
    }

    public FlowGraphNode getTo() {
        return _to;
    }

    public void setFrom(FlowGraphNode from) {
        _from = from;
    }

    public FlowGraphNode getFrom() {
        return _from;
    }

    public boolean changeScope() {
        return (_to.getScope() != _from.getScope());
    }

    public void setEdgeInfo(EdgeInfo info) {
        _edgeInfo = info;
    }
    
    public EdgeInfo getEdgeInfo() {
        return _edgeInfo;
    }
    
    public boolean isBack() {
        if(_edgeInfo != null && _edgeInfo.getType() == EdgeInfo.BACK) {
            return true;
        }
        return false;
    }
    
    public boolean isException() {
        if(_edgeInfo != null && _edgeInfo.getType() == EdgeInfo.EXCEPTION) {
            return true;
        }
        return false;
    }
    
    public void debug(DataOutputStream outs) {
        try {
            outs.writeInt(hashCode());
            if(_edgeInfo == null) {
                outs.writeBoolean(false);
            }
            else {
                outs.writeBoolean(true);
                _edgeInfo.debug(outs);
            }
        }
        catch(IOException ex) {
            System.out.println(ex);
        }
    }

    public void setDeleted() {
        _deleted = true;
    }
    
    public boolean isDeleted() {
        return _deleted;
    }
    
    
    public void setSDFDead() {
        _SDFDead = true;
    }
    
    public boolean isSDFDead() {
        return _SDFDead;
    }

    public String toString() {
        return new String("Edge from " + _from + "\n---->>>>>\n" + _to);
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    //// 

    ///////////////////////////////////////////////////////////////////
    ////                        private variables                  ////

    private FlowGraphNode _to;
    private FlowGraphNode _from;

    private EdgeInfo _edgeInfo;

    // Essa aresta nao deveria existir
    private boolean _deleted;
    private boolean _SDFDead = false;
}
